package com.sunyard.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @Descripstion:
 * @authorguangh.xu
 * @date:2018年7月23日 上午10:14:47
 **/
public class OrderUtil {

    private static final Logger logger = LoggerFactory.getLogger(OrderUtil.class);

    /**
     * @return
     */
    public static String orderNumber() {
        Date date1 = new Date();
        SimpleDateFormat df1 = new SimpleDateFormat("yyyyMMddHHmmss");
        String str = df1.format(date1);
        String str1 = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 18; i++) {
            int number = random.nextInt(10);
            sb.append(str1.charAt(number));
        }
        String serailNo = str + sb.toString();
//        logger.info("订单号为:" + serailNo);
        return serailNo;
    }

    /**
     * 生成30位的流水，清算文件核心的长度是30
     */
    public static String orderCoreNumber() {
        Date date1 = new Date();
        SimpleDateFormat df1 = new SimpleDateFormat("yyMMddHHmmss");
        String str = df1.format(date1);
        String str1 = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 18; i++) {
            int number = random.nextInt(10);
            sb.append(str1.charAt(number));
        }
        String serailNo = str + sb.toString();
        logger.info("订单号为:" + serailNo);
        return serailNo;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        String no = OrderUtil.orderCoreNumber();
        System.out.println(no.length());
    }

}
